package com.efei.jdbc.config;

import com.efei.jdbc.dynamic.query.dao.SysQueryDao;
import com.efei.jdbc.dynamic.query.dao.SysQueryDaoIml;
import com.efei.jdbc.dynamic.query.element.QueryElement;
import com.efei.jdbc.dynamic.query.service.SysQueryService;
import com.efei.jdbc.dynamic.query.web.SysQueryController;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 存放通用查询配置信息
 * @author xefei
 *
 */

@Configuration
public class SysQueryConfiguation {

    @Bean
    public SysQueryController sysQueryController() {
        return new SysQueryController();
    }

    @Bean
    public SysQueryService sysQueryService() {
        return new SysQueryService();
    }

    @Bean
    public SysQueryDao sysQueryDao() {
        return new SysQueryDaoIml();
    }

    protected final Map<String, QueryElement> queryElmentMap = new HashMap<String, QueryElement>();

    public QueryElement getQueryElment(String queryid) {
        return queryElmentMap.get(queryid);
    }

    public synchronized QueryElement addQueryElment(String queryid, QueryElement e, Boolean reput) {
        if(!reput) {
            QueryElement qe =  queryElmentMap.get(queryid);
            if(qe!=null) {
                return qe;
            }
        }

        queryElmentMap.put(queryid, e);
        return e;
    }
}
